/*
 * Copyright 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.deying.actionbarcompat;

import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.actionbarsherlock.internal.widget.IcsAdapterView;
import com.actionbarsherlock.internal.widget.IcsAdapterView.OnItemSelectedListener;
import com.deying.actionbarcompat.ActionBarHelperBase.SpinnerAdapterFactory;

public class MainActivity extends ActionBarActivity implements
		OnItemSelectedListener, SpinnerAdapterFactory {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		setTitle("xxxx");

		ActionBarHelperBase mActionBarHelperBase = (ActionBarHelperBase) this
				.getActionBarHelper();
		mActionBarHelperBase.setOnItemSelectedListener(this);
		mActionBarHelperBase.setSpinnerAdapterFactory(this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater menuInflater = getMenuInflater();
		menuInflater.inflate(R.menu.quotation_detail_menu, menu);

		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case com.deying.actionbarcompat.R.id.home:
			
			this.finish();

			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public BaseAdapter createAdapter() {
		// TODO Auto-generated method stub
		return new ArrayAdapter<String>(this,
				R.layout.spinner_dropdown_layout_1, R.id.text, getResources()
						.getStringArray(
								R.array.quotation_detail_menu_spinner_data));
	}

	@Override
	public void onItemSelected(IcsAdapterView<?> parent, View view,
			int position, long id) {
		// TODO Auto-generated method stub
		TextView tv = (TextView) view;
		tv.setBackgroundColor(Color.TRANSPARENT);
		tv.setTextColor(Color.WHITE);

	}

	@Override
	public void onNothingSelected(IcsAdapterView<?> parent) {
		// TODO Auto-generated method stub

	}

}
